<template>
  <a-modal
    title="新建字典"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :destroyOnClose="true"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="名称"
        >
          <a-input placeholder="名称" v-decorator="['name', {rules: [{required: true, message: '名称不能为空！'}]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="字典名称"
        >
          <a-input placeholder="字典名称" v-decorator="['dictKey', {rules: [{required: true, message: '字典名称不能为空！'}]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="字典值"
        >
          <a-input placeholder="字典值" v-decorator="['dictValue', {rules: [{required: true, message: '字典值不能为空！'}]}]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="描述"
        >
          <a-input placeholder="描述" v-decorator="['description',{rules: [{required: true, message: '描述不能为空！'}]}]" type="textarea"/>
        </a-form-item>
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建时间"
        >
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" placeholder="创建时间" @change="createdChange" v-decorator="['created_time',{rules: [{required: true, message: '创建时间不能为空！'}]}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建人"
        >
          <a-input placeholder="创建人" v-decorator="['created_by',{rules: [{required: true, message: '创建人不能为空！'}]}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="更新时间"
        >
          <a-date-picker
            showTime
            format="YYYY-MM-DD HH:mm:ss"
            placeholder="更新时间"
            v-decorator="['update_time',{rules: [{required: true, message: '更新时间不能为空！'}]}]"
            @change="updateChange"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="修改人"
        >
          <a-input placeholder="修改人" v-decorator="['update_by',{rules: [{required: true, message: '修改人不能为空！'}]}]"/>
        </a-form-item> -->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { addTDictionaries } from '@/api/dictionary'
export default {
  name: 'CreateDictionaryModal',
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this)
    }
  },

  // props: ['platTye'], // 接收父亲组建的值

  methods: {
    // 选中创建时间
    createdChange (value, dateString) {
      console.log('Formatted Selected Time: ', dateString)
    },
    // 选中创建时间
    updateChange (value, dateString) {
      console.log('Formatted Selected Time: ', dateString)
    },
    add () {
      this.visible = true
    },

    handleSubmit () {
      const { form: { validateFields } } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
          console.log('values----', values)
          addTDictionaries(values).then(res => {
            if (res) {
              // 存储成功、刷新列表
              this.$emit('ok', values)
              this.visible = false
              this.confirmLoading = false
              this.$notification['success']({
                message: '提示',
                description: '数据添加成功！'
              })
            }
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.visible = false
    }
  }
}
</script>
